package com.cxyzy.viewpager.showneighbour

import android.content.Context
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.PagerAdapter

class FlipFragmentAdapter(
        fragmentManager: FragmentManager, behavior: Int,
        private val context: Context, private val content: Array<String>?
) : FragmentStatePagerAdapter(fragmentManager, behavior) {
    override fun isViewFromObject(view: View, obj: Any): Boolean {
        return (obj as Fragment).view === view
    }

    override fun getItemPosition(obj: Any): Int {
        return PagerAdapter.POSITION_NONE
    }

    override fun getItem(position: Int): Fragment {
        return FlipFragment.newInstance(content!![position])
    }

    override fun getCount(): Int {
        return content?.size ?: 0
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return content!![position]
    }

}